﻿using System;
using Simhopp.Common;

namespace Simhopp.Common
{
    public static class ActiveCompetition
    {
        public static int CompetitionId { get; private set; }

        public static void LoadFromDatabase()
        {
            var res = MyDbConnection.ReadFromTable("select * from ActiveCompetition where Id='1'");
            try
            {
                CompetitionId = (int) res[0]["ActiveCompetition"];
            }
            catch (Exception)
            {
                CompetitionId = -1;
            }
        }

        public static void SaveToDatabase(int index)
        {
            CompetitionId = index;
            MyDbConnection.ExecuteUpdate(String.Format("update ActiveCompetition set ActiveCompetition='{0}' where Id='1'", index));
        }

    }
}
